'use client'
import type { FC } from 'react'
import React, { useEffect } from 'react'
import { usePathname } from 'next/navigation'
import useSWR from 'swr'
import { useTranslation } from 'react-i18next'
import {
  Cog8ToothIcon,
  // CommandLineIcon,
  Squares2X2Icon,
  // eslint-disable-next-line sort-imports
  PuzzlePieceIcon,
  DocumentTextIcon,
} from '@heroicons/react/24/outline'
import {
  Cog8ToothIcon as Cog8ToothSolidIcon,
  // CommandLineIcon as CommandLineSolidIcon,
  DocumentTextIcon as DocumentTextSolidIcon,
} from '@heroicons/react/24/solid'
import Link from 'next/link'
import s from './style.module.css'
import { fetchDataDetail, fetchDatasetRelatedApps } from '@/service/datasets'
import type { RelatedApp } from '@/models/datasets'
import { getLocaleOnClient } from '@/i18n/client'
import AppSideBar from '@/app/components/app-sidebar'
import Divider from '@/app/components/base/divider'
import Indicator from '@/app/components/header/indicator'
import AppIcon from '@/app/components/base/app-icon'
import Loading from '@/app/components/base/loading'
import DatasetDetailContext from '@/context/dataset-detail'
import { DataSourceType } from '@/models/datasets'
// import { fetchDatasetDetail } from '@/service/datasets'
export type IAppDetailLayoutProps = {
  children: React.ReactNode
  params: { datasetId: string }
}
const LikedItem: FC<{ type?: 'plugin' | 'app'; appStatus?: boolean; detail: RelatedApp }> = ({
  type = 'app',
  appStatus = true,
  detail,
}) => {
  return (
    
      
      {detail?.name || '--'}
    
  )
}
const TargetIcon: FC<{ className?: string }> = ({ className }) => {
  return 
}
const TargetSolidIcon: FC<{ className?: string }> = ({ className }) => {
  return 
}
const BookOpenIcon: FC<{ className?: string }> = ({ className }) => {
  return 
}
const DatasetDetailLayout: FC = (props) => {
  const {
    children,
    params: { datasetId },
  } = props
  const pathname = usePathname()
  const hideSideBar = /documents\/create$/.test(pathname)
  const { t } = useTranslation()
  const { data: datasetRes, error, mutate: mutateDatasetRes } = useSWR({
    action: 'fetchDataDetail',
    datasetId,
  }, apiParams => fetchDataDetail(apiParams.datasetId))
  const { data: relatedApps } = useSWR({
    action: 'fetchDatasetRelatedApps',
    datasetId,
  }, apiParams => fetchDatasetRelatedApps(apiParams.datasetId))
  const navigation = [
    { name: t('common.datasetMenus.documents'), href: `/datasets/${datasetId}/documents`, icon: DocumentTextIcon, selectedIcon: DocumentTextSolidIcon },
    { name: t('common.datasetMenus.hitTesting'), href: `/datasets/${datasetId}/hitTesting`, icon: TargetIcon, selectedIcon: TargetSolidIcon },
    // { name: 'api & webhook', href: `/datasets/${datasetId}/api`, icon: CommandLineIcon, selectedIcon: CommandLineSolidIcon },
    { name: t('common.datasetMenus.settings'), href: `/datasets/${datasetId}/settings`, icon: Cog8ToothIcon, selectedIcon: Cog8ToothSolidIcon },
  ]
  useEffect(() => {
    if (datasetRes)
      document.title = `${datasetRes.name || 'Dataset'} - Dify`
  }, [datasetRes])
  const ExtraInfo: FC = () => {
    const locale = getLocaleOnClient()
    return 
      
      {relatedApps?.data?.length
        ? (
          <>
            
{relatedApps?.total || '--'} {t('common.datasetMenus.relatedApp')}
            {relatedApps?.data?.map((item, index) => (
))}
          >
        )
        : (
          
        )}
    
 
  }
  if (!datasetRes && !error)
    return 
  return (
    
      {!hideSideBar && 
}
        iconType={datasetRes?.data_source_type === DataSourceType.NOTION ? 'notion' : 'dataset'}
      />}
      
 mutateDatasetRes(),
      }}>
        {children}